<template>
  <div class="width_99 mt_10">
    <div class="" v-if="showStatus">
      <el-row :gutter="10">
        <el-col :span="12">
          <el-card class="box-card" style="margin-bottom: 10px">
            <div class="fs_20 fwb">设备使用情况</div>
            <el-row class="mt_20">
              <el-col :span="6" class="tac">
                <img src="@/assets/images/a3207224.png" class="width_50" alt="" />
              </el-col>
              <el-col :span="6" class="tac">
                <div class="title">设备总数</div>
                <div class="fs_36 mt_20 fwb">
                  {{ deviceStats.deviceNum ? deviceStats.deviceNum : 0 }}
                  <span class="fs_16">台</span>
                </div>
              </el-col>
              <el-col :span="6" class="tac">
                <div class="title">在线数量</div>
                <div class="fs_36 mt_20 fwb">
                  {{ deviceStats.deviceOnlineNum ? deviceStats.deviceOnlineNum : 0 }}
                  <span class="fs_16">台</span>
                </div>
              </el-col>
              <el-col :span="6" class="tac">
                <div class="title">离线数量</div>
                <div class="fs_36 mt_20 fwb">
                  {{ deviceStats.deviceOfflineNum ? deviceStats.deviceOfflineNum : 0 }}
                  <span class="fs_16">台</span>
                </div>
              </el-col>
            </el-row>
          </el-card>
        </el-col>
        <el-col :span="12">
          <el-card class="box-card" style="margin-bottom: 10px">
            <div class="fs_20 fwb">师生人数统计</div>
            <el-row class="mt_20">
              <el-col :span="6" class="tac">
                <img src="@/assets/images/3069956b.png" class="width_50" alt="" />
              </el-col>
              <el-col :span="6" class="tac">
                <div class="title">师生总数</div>
                <div class="fs_36 mt_20 fwb">
                  {{ studentStats.studentNum ? studentStats.studentNum : 0 }}
                  <span class="fs_16">人</span>
                </div>
              </el-col>
              <el-col :span="6" class="tac">
                <div class="title">今日用餐人数</div>
                <div class="fs_36 mt_20 fwb">
                  {{ studentStats.todayDinersNum ? studentStats.todayDinersNum : 0
                  }}<span class="fs_16">人</span>
                </div>
              </el-col>
              <el-col :span="6" class="tac">
                <div class="title">今日新增人数</div>
                <div class="fs_36 mt_20 fwb">
                  {{ studentStats.todayAddedNum ? studentStats.todayAddedNum : 0
                  }}<span class="fs_16">人</span>
                </div>
              </el-col>
            </el-row>
          </el-card>
        </el-col>
      </el-row>
      <el-row :gutter="10">
        <el-col :span="6">
          <el-card class="box-card" style="margin-bottom: 10px">
            <el-row>
              <el-col :span="16">
                <div class="title">累计充值</div>
                <div class="fs_36 mt_20 fwb">
                  {{ tradeStats.totalRechargeNum ? tradeStats.totalRechargeNum : 0 }}
                  <span class="fs_16">元</span>
                </div>
              </el-col>
              <el-col :span="8" class="tac">
                <img src="@/assets/images/4bdb1535.png" class="width_50" alt="" />
              </el-col>
            </el-row>
          </el-card>
        </el-col>
        <el-col :span="6">
          <el-card class="box-card" style="margin-bottom: 10px">
            <el-row>
              <el-col :span="16">
                <div class="title">累计退款</div>
                <div class="fs_36 mt_20 fwb">
                  {{ tradeStats.totalRefundNum ? tradeStats.totalRefundNum : 0 }}
                  <span class="fs_16">元</span>
                </div>
              </el-col>
              <el-col :span="8" class="tac">
                <img src="@/assets/images/4bdb1535.png" class="width_50" alt="" />
              </el-col>
            </el-row>
          </el-card>
        </el-col>
        <el-col :span="6">
          <el-card class="box-card" style="margin-bottom: 10px">
            <el-row>
              <el-col :span="16">
                <div class="title">累计消费</div>
                <div class="fs_36 mt_20 fwb">
                  {{
                    tradeStats.totalConsumptionNum ? tradeStats.totalConsumptionNum : 0
                  }}
                  <span class="fs_16">元</span>
                </div>
              </el-col>
              <el-col :span="8" class="tac">
                <img src="@/assets/images/4bdb1535.png" class="width_50" alt="" />
              </el-col>
            </el-row>
          </el-card>
        </el-col>
        <el-col :span="6">
          <el-card class="box-card" style="margin-bottom: 10px">
            <el-row>
              <el-col :span="16">
                <div class="title">余额</div>
                <div class="fs_36 mt_20 fwb">
                  {{ tradeStats.balanceNum ? tradeStats.balanceNum : 0 }}
                  <span class="fs_16">元</span>
                </div>
              </el-col>
              <el-col :span="8" class="tac">
                <img src="@/assets/images/4bdb1535.png" class="width_50" alt="" />
              </el-col>
            </el-row>
          </el-card>
        </el-col>
      </el-row>
      <el-row :gutter="10">
        <el-col :span="3">
          <el-card class="box-card" style="margin-bottom: 10px">
            <el-row>
              <el-col :span="18">
                <div class="title">今日充值</div>
                <div class="fs_16 mt_20">
                  {{ tradeStats.todayRechargeNum ? tradeStats.todayRechargeNum : 0 }}
                  <span class="fs_16">元</span>
                </div>
              </el-col>
              <el-col :span="6" class="tac">
                <img
                  src=""
                  class="width_80"
                  alt=""
                />
              </el-col>
            </el-row>
          </el-card>
        </el-col>
        <el-col :span="3">
          <el-card class="box-card" style="margin-bottom: 10px">
            <el-row>
              <el-col :span="18">
                <div class="title">今日消费</div>
                <div class="fs_16 mt_20">
                  {{
                    tradeStats.todayConsumptionNum ? tradeStats.todayConsumptionNum : 0
                  }}
                  <span class="fs_16">元</span>
                </div>
              </el-col>
              <el-col :span="6" class="tac">
                <img
                  src=""
                  class="width_80"
                  alt=""
                />
              </el-col>
            </el-row>
          </el-card>
        </el-col>
        <el-col :span="3">
          <el-card class="box-card" style="margin-bottom: 10px">
            <el-row>
              <el-col :span="18">
                <div class="title">本月充值</div>
                <div class="fs_16 mt_20">
                  {{
                    tradeStats.thisMonthRechargeNum ? tradeStats.thisMonthRechargeNum : 0
                  }}
                  <span class="fs_16">元</span>
                </div>
              </el-col>
              <el-col :span="6" class="tac">
                <img
                  src=""
                  class="width_80"
                  alt=""
                />
              </el-col>
            </el-row>
          </el-card>
        </el-col>
        <el-col :span="3">
          <el-card class="box-card" style="margin-bottom: 10px">
            <el-row>
              <el-col :span="18">
                <div class="title">本月消费</div>
                <div class="fs_16 mt_20">
                  {{
                    tradeStats.thisMonthConsumptionNum
                      ? tradeStats.thisMonthConsumptionNum
                      : 0
                  }}
                  <span class="fs_16">元</span>
                </div>
              </el-col>
              <el-col :span="6" class="tac">
                <img
                  src=""
                  class="width_80"
                  alt=""
                />
              </el-col>
            </el-row>
          </el-card>
        </el-col>
        <el-col :span="3">
          <el-card class="box-card" style="margin-bottom: 10px">
            <el-row>
              <el-col :span="18">
                <div class="title">本月退款</div>
                <div class="fs_16 mt_20">
                  {{ tradeStats.thisMonthRefundNum ? tradeStats.thisMonthRefundNum : 0 }}
                  <span class="fs_16">元</span>
                </div>
              </el-col>
              <el-col :span="6" class="tac">
                <img
                  src=""
                  class="width_80"
                  alt=""
                />
              </el-col>
            </el-row>
          </el-card>
        </el-col>
        <el-col :span="3">
          <el-card class="box-card" style="margin-bottom: 10px">
            <el-row>
              <el-col :span="18">
                <div class="title">上月充值</div>
                <div class="fs_16 mt_20">
                  {{
                    tradeStats.lastMonthRechargeNum ? tradeStats.lastMonthRechargeNum : 0
                  }}
                  <span>元</span>
                </div>
              </el-col>
              <el-col :span="6" class="tac">
                <img
                  src=""
                  class="width_80"
                  alt=""
                />
              </el-col>
            </el-row>
          </el-card>
        </el-col>
        <el-col :span="3">
          <el-card class="box-card" style="margin-bottom: 10px">
            <el-row>
              <el-col :span="18">
                <div class="title">上月消费</div>
                <div class="fs_16 mt_20">
                  {{
                    tradeStats.lastMonthConsumptionNum
                      ? tradeStats.lastMonthConsumptionNum
                      : 0
                  }}
                  <span>元</span>
                </div>
              </el-col>
              <el-col :span="6" class="tac">
                <img
                  src=""
                  class="width_80"
                  alt=""
                />
              </el-col>
            </el-row>
          </el-card>
        </el-col>
        <el-col :span="3">
          <el-card class="box-card" style="margin-bottom: 10px">
            <el-row>
              <el-col :span="18">
                <div class="title">上月退款</div>
                <div class="fs_16 mt_20">
                  {{ tradeStats.lastMonthRefundNum ? tradeStats.lastMonthRefundNum : 0 }}
                  <span class="fs_16">元</span>
                </div>
              </el-col>
              <el-col :span="6" class="tac">
                <img
                  src=""
                  class="width_80"
                  alt=""
                />
              </el-col>
            </el-row>
          </el-card>
        </el-col>
      </el-row>
      <el-card class="box-card" style="margin-bottom: 10px">
        <div class="width_96" id="echarts_1" style="width: 100%; height: 400px"></div>
      </el-card>
      <div class="box_height"></div>
    </div>
  </div>
</template>
<script>
import * as echarts from "echarts";
import { campusHomeStats } from "@/api/index/index";
export default {
  name: "Index",
  components: {},
  data() {
    return {
      deviceStats: [],
      studentStats: [],
      tradeStats: [],
      inOutRecordChart: [],
      userId: "",
      showStatus: false,
    };
  },
  mounted() {
    this.userId = window.sessionStorage.getItem("userId");
    if (this.userId == "109") {
      this.showStatus = false;
      return;
    }
    if (this.userId == "108") {
      this.showStatus = false;
      return;
    }
    if (this.userId != "109" && this.userId != "108") {
      this.showStatus = true;
      this.homeFun();
    }
  },
  methods: {
    homeFun() {
      var that = this;
      campusHomeStats().then((response) => {
        if (response.code == 200) {
          that.deviceStats = response.data.deviceStats;
          that.studentStats = response.data.studentStats;
          var tradeStats = response.data.tradeStats;
          tradeStats.totalRechargeNum =
            parseFloat(tradeStats.totalRechargeNum * 100).toFixed(2) / 100;
          this.tradeStats = tradeStats;
          that.inOutRecordChart = response.data.tradeStats.inOutRecordChart;
          that.echartFun();
        }
      });
    },
    echartFun() {
      var that = this;
      var chartDom = document.getElementById("echarts_1");
      var myChart = echarts.init(chartDom);
      var option = {
        title: {
          text: "收支记录",
        },
        grid: {
          left: "1%",
          right: "1%",
          bottom: "1%",
          containLabel: true,
        },
        legend: {
          data: ["充值", "消费"],
        },
        tooltip: {
          trigger: "axis",
        },
        xAxis: {
          type: "category",
          data: that.inOutRecordChart.xdata,
        },
        yAxis: {
          type: "value",
        },
        series: [
          {
            name: "充值",
            data: that.inOutRecordChart.ydataIn,
            type: "line",
            smooth: true,
          },
          {
            name: "消费",
            data: that.inOutRecordChart.ydataOut,
            type: "line",
            smooth: true,
          },
        ],
      };
      option && myChart.setOption(option);
    },
  },
};
</script>

<style lang="scss" scoped>
.width_100 {
  width: 100%;
}
.width_50 {
  width: 50%;
}
.width_80 {
  width: 80%;
}
.width_99 {
  width: 99%;
  margin: 0 auto;
}
.width_96 {
  width: 96%;
  margin: 0 auto;
}
.mt_10 {
  margin-top: 10px;
}
.mt_20 {
  margin-top: 20px;
}
.tac {
  text-align: center;
}
.fs_36 {
  font-size: 36px;
}
.fs_24 {
  font-size: 24px;
}
.fs_20 {
  font-size: 20px;
}
.fwb {
  font-weight: bold;
}
.title {
  color: #7d7b7b;
  font-size: 16px;
}
.fs_16 {
  font-size: 16px;
}
.box_height {
  height: 100px;
}
</style>
